﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Data;

namespace RubricaSentimentale
{
    public partial class AggiungiDettagli : PhoneApplicationPage
    {
        ViewModel vm;
        Details d = new Details();
        DataDetails dd = new DataDetails();
        TextBox tbx = new TextBox();

        public AggiungiDettagli()
        {
            
            InitializeComponent();
            vm = (ViewModel)Utility.LoadState("ViewModel");
            this.Loaded += new RoutedEventHandler(AggiungiDettagli_Loaded);
            
        }

        void AggiungiDettagli_Loaded(object sender, RoutedEventArgs e)
        {
            //Container.Height = this.Height - 200;
            d.Margin = new Thickness();
            d.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
            d.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            d.Width = double.NaN;
            d.Height = Container.ActualHeight;
            dd.Margin = new Thickness();
            dd.Width = double.NaN;
            dd.Height = Container.ActualHeight;
            dd.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;
            dd.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;

            Binding bind = new Binding("Value");
            bind.Source = vm.Current.Note;
            bind.Mode = BindingMode.TwoWay;
            BindingOperations.SetBinding(tbx, TextBox.TextProperty, bind);
            tbx.Margin = new Thickness();
            tbx.Height = double.NaN;
            tbx.Width = double.NaN;
            tbx.AcceptsReturn = true;
            tbx.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            tbx.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

            btnFilms.Click += new RoutedEventHandler(btnFilms_Click);
            btnDate.Click += new RoutedEventHandler(btnDate_Click);
            btnNote.Click += new RoutedEventHandler(btnNote_Click);
            btnCibi.Click += new RoutedEventHandler(btnCibi_Click);
        }

        void btnCibi_Click(object sender, RoutedEventArgs e)
        {
            d.DataContext = vm.Current.Food;
            d.tbxDettaglio.Text = "";
            Container.Children.Clear();
            Container.Children.Add(d);
        }

        void btnNote_Click(object sender, RoutedEventArgs e)
        {
            tbx.DataContext = vm.Current.Note;
            Container.Children.Clear();
            Container.Children.Add(tbx);
        }

        void btnDate_Click(object sender, RoutedEventArgs e)
        {
            dd.DataContext = vm.Current.Date;
            Container.Children.Clear();
            Container.Children.Add(dd);
        }

        void btnFilms_Click(object sender, RoutedEventArgs e)
        {
            d.DataContext = vm.Current.Films;
            d.tbxDettaglio.Text = "";
            Container.Children.Clear();
            Container.Children.Add(d);
        }

        protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
        {
            e.Cancel = false;
            Utility.Save(vm, typeof(ViewModel));
            base.OnBackKeyPress(e);
        }
    }
}
